package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.FitExercise;
import com.ruoyi.system.service.IFitExerciseService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 健身记录Controller
 * 
 * @author ruoyi
 * @date 2025-05-14
 */
@Controller
@RequestMapping("/system/exercise")
public class FitExerciseController extends BaseController
{
    private String prefix = "system/exercise";

    @Autowired
    private IFitExerciseService fitExerciseService;

    @RequiresPermissions("system:exercise:view")
    @GetMapping()
    public String exercise()
    {
        return prefix + "/exercise";
    }

    /**
     * 查询健身记录列表
     */
    @RequiresPermissions("system:exercise:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FitExercise fitExercise)
    {
        startPage();
        List<FitExercise> list = fitExerciseService.selectFitExerciseList(fitExercise);
        return getDataTable(list);
    }

    /**
     * 导出健身记录列表
     */
    @RequiresPermissions("system:exercise:export")
    @Log(title = "健身记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FitExercise fitExercise)
    {
        List<FitExercise> list = fitExerciseService.selectFitExerciseList(fitExercise);
        ExcelUtil<FitExercise> util = new ExcelUtil<FitExercise>(FitExercise.class);
        return util.exportExcel(list, "健身记录数据");
    }

    /**
     * 新增健身记录
     */
    @RequiresPermissions("system:exercise:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存健身记录
     */
    @RequiresPermissions("system:exercise:add")
    @Log(title = "健身记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FitExercise fitExercise)
    {
        return toAjax(fitExerciseService.insertFitExercise(fitExercise));
    }

    /**
     * 修改健身记录
     */
    @RequiresPermissions("system:exercise:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        FitExercise fitExercise = fitExerciseService.selectFitExerciseById(id);
        mmap.put("fitExercise", fitExercise);
        return prefix + "/edit";
    }

    /**
     * 修改保存健身记录
     */
    @RequiresPermissions("system:exercise:edit")
    @Log(title = "健身记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FitExercise fitExercise)
    {
        return toAjax(fitExerciseService.updateFitExercise(fitExercise));
    }

    /**
     * 删除健身记录
     */
    @RequiresPermissions("system:exercise:remove")
    @Log(title = "健身记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fitExerciseService.deleteFitExerciseByIds(ids));
    }
}
